package com.wisezone.java1902.d13_sort1;
/**
 * 用户 实体类
 * */
public class User implements Comparable<User>{
	private String name; //姓名
	private int age; //年龄
    
	public User() {
		
	}
	
	public User(String name, int age) {
		this.name = name;
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "User [name=" + name + ", age=" + age + "]";
	}

	@Override
	public int compareTo(User o) {
		if(this.getAge() > o.getAge()) {
			return 1; //返回正数, o2排o1前面
		}else if(this.getAge() < o.getAge()) {
			return -1; //返回负数，o1排o2前面
		}else {
			return 0; //返回0按照原来规则排序
		}
	}
	
	
}
